// Three.js r167 - Node System


diagnostic( off, derivative_uniformity );

// uniforms
@binding( 0 ) @group( 0 ) var nodeUniform9_sampler : sampler;
@binding( 1 ) @group( 0 ) var nodeUniform9 : texture_2d<f32>;
@binding( 3 ) @group( 0 ) var nodeUniform19 : texture_2d<f32>;
@binding( 4 ) @group( 0 ) var nodeUniform21 : texture_2d<f32>;
struct objectStruct {
	nodeUniform10 : mat3x3<f32>,
	nodeUniform11 : f32,
	nodeUniform12 : vec3<f32>,
	nodeUniform13 : f32,
	nodeUniform14 : f32,
	nodeUniform15 : f32,
	nodeUniform16 : vec3<f32>,
	nodeUniform17 : f32,
	nodeUniform20 : mat3x3<f32>,
	nodeUniform22 : mat3x3<f32>,
	nodeUniform23 : vec3<f32>,
	nodeUniform24 : vec3<f32>,
	nodeUniform25 : vec3<f32>,
	nodeUniform26 : vec3<f32>,
	nodeUniform27 : mat3x3<f32>,
	nodeUniform28 : mat3x3<f32>,
	nodeUniform29 : vec3<f32>,
	nodeUniform30 : vec3<f32>,
	nodeUniform31 : vec3<f32>,
	nodeUniform32 : vec3<f32>,
	nodeUniform33 : mat3x3<f32>,
	nodeUniform34 : mat3x3<f32>,
	nodeUniform35 : vec3<f32>,
	nodeUniform36 : vec3<f32>,
	nodeUniform37 : vec3<f32>,
	nodeUniform38 : vec3<f32>
};
@binding( 2 ) @group( 0 )
var<uniform> object : objectStruct;

// structs

struct OutputStruct {
	@location(0) color: vec4<f32>
};
var<private> output : OutputStruct;



// codes
fn LTC_Uv ( N : vec3<f32>, V : vec3<f32>, roughness : f32 ) -> vec2<f32> {

	var nodeVar0 : vec2<f32>;

	nodeVar0 = vec2<f32>( roughness, sqrt( ( 1.0 - clamp( dot( N, V ), 0.0, 1.0 ) ) ) );
	nodeVar0 = ( ( nodeVar0 * vec2<f32>( 0.984375 ) ) + vec2<f32>( 0.0078125 ) );

	return nodeVar0;

}


fn threejs_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {

	let uvScaled = vec2<u32>( uv * vec2<f32>( dimension ) );

	return ( ( uvScaled % dimension ) + dimension ) % dimension;

}

fn LTC_EdgeVectorFormFactor ( v1 : vec3<f32>, v2 : vec3<f32> ) -> vec3<f32> {

	var nodeVar0 : f32;
	var nodeVar1 : f32;
	var nodeVar2 : f32;
	var nodeVar3 : f32;
	var nodeVar4 : f32;

	nodeVar1 = dot( v1, v2 );
	nodeVar0 = abs( nodeVar1 );
	nodeVar2 = ( ( ( ( nodeVar0 * 0.0145206 ) + 0.4965155 ) * nodeVar0 ) + 0.8543985 );
	nodeVar3 = ( ( ( nodeVar0 + 4.1616724 ) * nodeVar0 ) + 3.417594 );

	if ( ( nodeVar1 > 0.0 ) ) {

		nodeVar4 = ( nodeVar2 / nodeVar3 );

	} else {

		nodeVar4 = ( ( inverseSqrt( max( ( 1.0 - ( nodeVar1 * nodeVar1 ) ), 1e-7 ) ) * 0.5 ) - ( nodeVar2 / nodeVar3 ) );

	}


	return ( cross( v1, v2 ) * vec3<f32>( nodeVar4 ) );

}

fn LTC_ClippedSphereFormFactor ( f : vec3<f32> ) -> f32 {

	var nodeVar0 : f32;

	nodeVar0 = length( f );

	return max( ( ( ( nodeVar0 * nodeVar0 ) + f.z ) / ( nodeVar0 + 1.0 ) ), 0.0 );

}

fn LTC_Evaluate ( N : vec3<f32>, V : vec3<f32>, P : vec3<f32>, mInv : mat3x3<f32>, p0 : vec3<f32>, p1 : vec3<f32>, p2 : vec3<f32>, p3 : vec3<f32> ) -> vec3<f32> {

	var nodeVar0 : vec3<f32>;
	var nodeVar1 : vec3<f32>;
	var nodeVar2 : vec3<f32>;
	var nodeVar3 : mat3x3<f32>;
	var nodeVar4 : vec3<f32>;
	var nodeVar5 : vec3<f32>;
	var nodeVar6 : vec3<f32>;
	var nodeVar7 : vec3<f32>;
	var nodeVar8 : vec3<f32>;
	var nodeVar9 : vec3<f32>;

	nodeVar0 = ( p1 - p0 );
	nodeVar1 = ( p3 - p0 );
	nodeVar2 = vec3<f32>( 0.0, 0.0, 0.0 );

	if ( ( dot( cross( nodeVar0, nodeVar1 ), ( P - p0 ) ) >= 0.0 ) ) {

		nodeVar4 = normalize( ( V - ( N * vec3<f32>( dot( V, N ) ) ) ) );
		nodeVar3 = ( mInv * transpose( mat3x3<f32>( nodeVar4, ( - cross( N, nodeVar4 ) ), N ) ) );
		nodeVar5 = normalize( ( nodeVar3 * ( p0 - P ) ) );
		nodeVar6 = normalize( ( nodeVar3 * ( p1 - P ) ) );
		nodeVar7 = normalize( ( nodeVar3 * ( p2 - P ) ) );
		nodeVar8 = normalize( ( nodeVar3 * ( p3 - P ) ) );
		nodeVar9 = vec3<f32>( 0.0, 0.0, 0.0 );
		nodeVar9 = ( nodeVar9 + LTC_EdgeVectorFormFactor( nodeVar5, nodeVar6 ) );
		nodeVar9 = ( nodeVar9 + LTC_EdgeVectorFormFactor( nodeVar6, nodeVar7 ) );
		nodeVar9 = ( nodeVar9 + LTC_EdgeVectorFormFactor( nodeVar7, nodeVar8 ) );
		nodeVar9 = ( nodeVar9 + LTC_EdgeVectorFormFactor( nodeVar8, nodeVar5 ) );
		nodeVar2 = vec3<f32>( LTC_ClippedSphereFormFactor( nodeVar9 ) );
		

	}


	return nodeVar2;

}

fn DFGApprox ( roughness : f32, dotNV : vec3<f32> ) -> vec2<f32> {

	var nodeVar0 : vec4<f32>;

	nodeVar0 = ( ( roughness * vec4<f32>( -1.0, -0.0275, -0.572, 0.022 ) ) + vec4<f32>( 1.0, 0.0425, 1.04, -0.04 ) );

	return ( ( vec3<f32>( vec2<f32>( -1.04, 1.04 ), 0.0 ) * ( ( min( vec3<f32>( ( nodeVar0.x * nodeVar0.x ) ), exp2( ( dotNV * vec3<f32>( -9.28 ) ) ) ) * vec3<f32>( nodeVar0.x ) ) + vec3<f32>( nodeVar0.y ) ) ) + vec3<f32>( nodeVar0.zw, 0.0 ) ).xy;

}



@fragment
fn main( @location( 0 ) v_normalView : vec3<f32>,
	@location( 1 ) v_positionView : vec3<f32>,
	@location( 2 ) v_positionViewDirection : vec3<f32>,
	@location( 3 ) vInstanceOpacity : f32,
	@location( 4 ) vInstanceIndexOpacity : f32,
	@location( 5 ) vInstanceIndex : f32,
	@location( 6 ) nodeVarying6 : vec2<f32>,
	@location( 7 ) @interpolate( flat ) nodeVarying7 : u32,
	@location( 8 ) nodeVarying8 : vec3<f32>,
	@builtin( front_facing ) isFront : bool ) -> OutputStruct {

	// vars
	
	var transformedNormalView : vec3<f32>;
	var normalView : vec3<f32>;
	var DiffuseColor : vec4<f32>;
	var nodeVar3 : vec4<f32>;
	var Metalness : f32;
	var Roughness : f32;
	var nodeVar6 : vec3<f32>;
	var SpecularColor : vec3<f32>;
	var SpecularF90 : f32;
	var EmissiveColor : vec3<f32>;
	var Output : vec4<f32>;
	var nodeVar11 : vec3<f32>;
	var nodeVar12 : vec4<f32>;
	var positionViewDirection : vec3<f32>;
	var nodeVar14 : vec4<f32>;
	var nodeVar15 : vec4<f32>;
	var nodeVar16 : vec4<f32>;
	var nodeVar17 : mat3x3<f32>;
	var nodeVar18 : vec3<f32>;
	var directSpecular : vec3<f32>;
	var nodeVar20 : vec3<f32>;
	var nodeVar21 : vec3<f32>;
	var nodeVar22 : vec3<f32>;
	var nodeVar23 : vec3<f32>;
	var directDiffuse : vec3<f32>;
	var nodeVar25 : vec3<f32>;
	var nodeVar26 : vec4<f32>;
	var nodeVar27 : vec4<f32>;
	var nodeVar28 : vec4<f32>;
	var nodeVar29 : vec4<f32>;
	var nodeVar30 : mat3x3<f32>;
	var nodeVar31 : vec3<f32>;
	var nodeVar32 : vec3<f32>;
	var nodeVar33 : vec3<f32>;
	var nodeVar34 : vec3<f32>;
	var nodeVar35 : vec3<f32>;
	var nodeVar36 : vec3<f32>;
	var nodeVar37 : vec4<f32>;
	var nodeVar38 : vec4<f32>;
	var nodeVar39 : vec4<f32>;
	var nodeVar40 : vec4<f32>;
	var nodeVar41 : mat3x3<f32>;
	var nodeVar42 : vec3<f32>;
	var nodeVar43 : vec3<f32>;
	var nodeVar44 : vec3<f32>;
	var nodeVar45 : vec3<f32>;
	var nodeVar46 : vec3<f32>;
	var indirectDiffuse : vec3<f32>;
	var irradiance : vec3<f32>;
	var singleScattering : vec3<f32>;
	var nodeVar50 : vec3<f32>;
	var multiScattering : vec3<f32>;
	var nodeVar52 : vec3<f32>;
	var nodeVar53 : f32;
	var indirectSpecular : vec3<f32>;
	var radiance : vec3<f32>;
	var iblIrradiance : vec3<f32>;
	var nodeVar57 : vec3<f32>;
	var nodeVar58 : vec3<f32>;
	var ambientOcclusion : f32;
	var totalDiffuse : vec3<f32>;
	var totalSpecular : vec3<f32>;
	var outgoingLight : vec3<f32>;
	var nodeVar63 : vec4<f32>;


	// flow
	// code

	normalView = normalize( v_normalView );
	transformedNormalView = ( normalView * vec3<f32>( ( ( f32( isFront ) * 2.0 ) - 1.0 ) ) );
	nodeVar3 = textureSample( nodeUniform9, nodeUniform9_sampler, ( object.nodeUniform10 * vec3<f32>( nodeVarying6, 1.0 ) ).xy );
	DiffuseColor = nodeVar3;
	DiffuseColor.w = ( ( ( DiffuseColor.w * object.nodeUniform11 ) * vInstanceIndexOpacity ) * vInstanceOpacity );
	DiffuseColor = mix( DiffuseColor, vec4<f32>( object.nodeUniform12, step( abs( dot( normalize( vec3<f32>( 0.0, 0.0, 1.0 ) ), transformedNormalView ) ), object.nodeUniform13 ) ), f32( ( nodeVarying7 / nodeVarying7 ) ) );
	Metalness = object.nodeUniform14;
	nodeVar6 = max( abs( dpdx( nodeVarying8 ) ), abs( - dpdy( nodeVarying8 ) ) );
	Roughness = min( ( max( object.nodeUniform15, 0.0525 ) + max( max( nodeVar6.x, nodeVar6.y ), nodeVar6.z ) ), 1.0 );
	SpecularColor = mix( vec3<f32>( 0.04, 0.04, 0.04 ), DiffuseColor.xyz, Metalness );
	SpecularF90 = 1.0;
	DiffuseColor = vec4<f32>( ( DiffuseColor.xyz * vec3<f32>( ( 1.0 - object.nodeUniform14 ) ) ), DiffuseColor.w );
	EmissiveColor = ( object.nodeUniform16 * vec3<f32>( object.nodeUniform17 ) );
	nodeVar11 = v_positionView;
	positionViewDirection = normalize( v_positionViewDirection );
	nodeVar14 = textureLoad( nodeUniform19, threejs_repeatWrapping( ( object.nodeUniform20 * vec3<f32>( LTC_Uv( transformedNormalView, positionViewDirection, Roughness ), 1.0 ) ).xy, textureDimensions( nodeUniform19, 0 ) ), i32( 0 ) );
	nodeVar12 = nodeVar14;
	nodeVar16 = textureLoad( nodeUniform21, threejs_repeatWrapping( ( object.nodeUniform22 * vec3<f32>( LTC_Uv( transformedNormalView, positionViewDirection, Roughness ), 1.0 ) ).xy, textureDimensions( nodeUniform21, 0 ) ), i32( 0 ) );
	nodeVar15 = nodeVar16;
	nodeVar17 = mat3x3<f32>( vec3<f32>( nodeVar12.x, 0.0, nodeVar12.y ), vec3<f32>( 0.0, 1.0, 0.0 ), vec3<f32>( nodeVar12.z, 0.0, nodeVar12.w ) );
	nodeVar18 = ( ( SpecularColor * vec3<f32>( nodeVar15.x ) ) + ( ( vec3<f32>( 1.0 ) - SpecularColor ) * vec3<f32>( nodeVar15.y ) ) );
	directSpecular = vec3<f32>( 0.0, 0.0, 0.0 );
	nodeVar20 = ( ( object.nodeUniform24 + object.nodeUniform25 ) - object.nodeUniform26 );
	nodeVar21 = ( ( object.nodeUniform24 - object.nodeUniform25 ) - object.nodeUniform26 );
	nodeVar22 = ( ( object.nodeUniform24 - object.nodeUniform25 ) + object.nodeUniform26 );
	nodeVar23 = ( ( object.nodeUniform24 + object.nodeUniform25 ) + object.nodeUniform26 );
	directSpecular = ( directSpecular + ( ( object.nodeUniform23 * nodeVar18 ) * LTC_Evaluate( transformedNormalView, positionViewDirection, nodeVar11, nodeVar17, nodeVar20, nodeVar21, nodeVar22, nodeVar23 ) ) );
	directDiffuse = vec3<f32>( 0.0, 0.0, 0.0 );
	directDiffuse = ( vec4<f32>( directDiffuse, 1.0 ) + ( ( vec4<f32>( object.nodeUniform23, 1.0 ) * DiffuseColor ) * vec4<f32>( LTC_Evaluate( transformedNormalView, positionViewDirection, nodeVar11, mat3x3<f32>( 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ), nodeVar20, nodeVar21, nodeVar22, nodeVar23 ), 1.0 ) ) ).xyz;
	nodeVar25 = v_positionView;
	nodeVar27 = textureLoad( nodeUniform19, threejs_repeatWrapping( ( object.nodeUniform27 * vec3<f32>( LTC_Uv( transformedNormalView, positionViewDirection, Roughness ), 1.0 ) ).xy, textureDimensions( nodeUniform19, 0 ) ), i32( 0 ) );
	nodeVar26 = nodeVar27;
	nodeVar29 = textureLoad( nodeUniform21, threejs_repeatWrapping( ( object.nodeUniform28 * vec3<f32>( LTC_Uv( transformedNormalView, positionViewDirection, Roughness ), 1.0 ) ).xy, textureDimensions( nodeUniform21, 0 ) ), i32( 0 ) );
	nodeVar28 = nodeVar29;
	nodeVar30 = mat3x3<f32>( vec3<f32>( nodeVar26.x, 0.0, nodeVar26.y ), vec3<f32>( 0.0, 1.0, 0.0 ), vec3<f32>( nodeVar26.z, 0.0, nodeVar26.w ) );
	nodeVar31 = ( ( SpecularColor * vec3<f32>( nodeVar28.x ) ) + ( ( vec3<f32>( 1.0 ) - SpecularColor ) * vec3<f32>( nodeVar28.y ) ) );
	nodeVar32 = ( ( object.nodeUniform30 + object.nodeUniform31 ) - object.nodeUniform32 );
	nodeVar33 = ( ( object.nodeUniform30 - object.nodeUniform31 ) - object.nodeUniform32 );
	nodeVar34 = ( ( object.nodeUniform30 - object.nodeUniform31 ) + object.nodeUniform32 );
	nodeVar35 = ( ( object.nodeUniform30 + object.nodeUniform31 ) + object.nodeUniform32 );
	directSpecular = ( directSpecular + ( ( object.nodeUniform29 * nodeVar31 ) * LTC_Evaluate( transformedNormalView, positionViewDirection, nodeVar25, nodeVar30, nodeVar32, nodeVar33, nodeVar34, nodeVar35 ) ) );
	directDiffuse = ( vec4<f32>( directDiffuse, 1.0 ) + ( ( vec4<f32>( object.nodeUniform29, 1.0 ) * DiffuseColor ) * vec4<f32>( LTC_Evaluate( transformedNormalView, positionViewDirection, nodeVar25, mat3x3<f32>( 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ), nodeVar32, nodeVar33, nodeVar34, nodeVar35 ), 1.0 ) ) ).xyz;
	nodeVar36 = v_positionView;
	nodeVar38 = textureLoad( nodeUniform19, threejs_repeatWrapping( ( object.nodeUniform33 * vec3<f32>( LTC_Uv( transformedNormalView, positionViewDirection, Roughness ), 1.0 ) ).xy, textureDimensions( nodeUniform19, 0 ) ), i32( 0 ) );
	nodeVar37 = nodeVar38;
	nodeVar40 = textureLoad( nodeUniform21, threejs_repeatWrapping( ( object.nodeUniform34 * vec3<f32>( LTC_Uv( transformedNormalView, positionViewDirection, Roughness ), 1.0 ) ).xy, textureDimensions( nodeUniform21, 0 ) ), i32( 0 ) );
	nodeVar39 = nodeVar40;
	nodeVar41 = mat3x3<f32>( vec3<f32>( nodeVar37.x, 0.0, nodeVar37.y ), vec3<f32>( 0.0, 1.0, 0.0 ), vec3<f32>( nodeVar37.z, 0.0, nodeVar37.w ) );
	nodeVar42 = ( ( SpecularColor * vec3<f32>( nodeVar39.x ) ) + ( ( vec3<f32>( 1.0 ) - SpecularColor ) * vec3<f32>( nodeVar39.y ) ) );
	nodeVar43 = ( ( object.nodeUniform36 + object.nodeUniform37 ) - object.nodeUniform38 );
	nodeVar44 = ( ( object.nodeUniform36 - object.nodeUniform37 ) - object.nodeUniform38 );
	nodeVar45 = ( ( object.nodeUniform36 - object.nodeUniform37 ) + object.nodeUniform38 );
	nodeVar46 = ( ( object.nodeUniform36 + object.nodeUniform37 ) + object.nodeUniform38 );
	directSpecular = ( directSpecular + ( ( object.nodeUniform35 * nodeVar42 ) * LTC_Evaluate( transformedNormalView, positionViewDirection, nodeVar36, nodeVar41, nodeVar43, nodeVar44, nodeVar45, nodeVar46 ) ) );
	directDiffuse = ( vec4<f32>( directDiffuse, 1.0 ) + ( ( vec4<f32>( object.nodeUniform35, 1.0 ) * DiffuseColor ) * vec4<f32>( LTC_Evaluate( transformedNormalView, positionViewDirection, nodeVar36, mat3x3<f32>( 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ), nodeVar43, nodeVar44, nodeVar45, nodeVar46 ), 1.0 ) ) ).xyz;
	indirectDiffuse = vec3<f32>( 0.0, 0.0, 0.0 );
	irradiance = vec3<f32>( 0.0, 0.0, 0.0 );
	indirectDiffuse = ( vec4<f32>( indirectDiffuse, 1.0 ) + ( vec4<f32>( irradiance, 1.0 ) * ( DiffuseColor * vec4<f32>( 0.3183098861837907 ) ) ) ).xyz;
	singleScattering = vec3<f32>( 0.0, 0.0, 0.0 );
	nodeVar50 = ( ( SpecularColor * vec3<f32>( DFGApprox( Roughness, vec3<f32>( clamp( dot( transformedNormalView, positionViewDirection ), 0.0, 1.0 ) ) ).x ) ) + vec3<f32>( ( SpecularF90 * DFGApprox( Roughness, vec3<f32>( clamp( dot( transformedNormalView, positionViewDirection ), 0.0, 1.0 ) ) ).y ) ) );
	singleScattering = ( singleScattering + nodeVar50 );
	multiScattering = vec3<f32>( 0.0, 0.0, 0.0 );
	nodeVar52 = ( SpecularColor + ( ( vec3<f32>( 1.0 ) - SpecularColor ) * vec3<f32>( 0.047619 ) ) );
	nodeVar53 = ( 1.0 - ( DFGApprox( Roughness, vec3<f32>( clamp( dot( transformedNormalView, positionViewDirection ), 0.0, 1.0 ) ) ).x + DFGApprox( Roughness, vec3<f32>( clamp( dot( transformedNormalView, positionViewDirection ), 0.0, 1.0 ) ) ).y ) );
	multiScattering = ( multiScattering + ( ( ( nodeVar50 * nodeVar52 ) / ( vec3<f32>( 1.0 ) - ( vec3<f32>( nodeVar53 ) * nodeVar52 ) ) ) * vec3<f32>( nodeVar53 ) ) );
	indirectSpecular = vec3<f32>( 0.0, 0.0, 0.0 );
	radiance = vec3<f32>( 0.0, 0.0, 0.0 );
	indirectSpecular = ( indirectSpecular + ( radiance * singleScattering ) );
	iblIrradiance = vec3<f32>( 0.0, 0.0, 0.0 );
	nodeVar57 = ( iblIrradiance * vec3<f32>( 0.3183098861837907 ) );
	indirectSpecular = ( indirectSpecular + ( multiScattering * nodeVar57 ) );
	nodeVar58 = ( singleScattering + multiScattering );
	indirectDiffuse = ( vec4<f32>( indirectDiffuse, 1.0 ) + ( ( DiffuseColor * vec4<f32>( ( 1.0 - max( max( nodeVar58.x, nodeVar58.y ), nodeVar58.z ) ) ) ) * vec4<f32>( nodeVar57, 1.0 ) ) ).xyz;
	ambientOcclusion = 1.0;
	indirectDiffuse = ( indirectDiffuse * vec3<f32>( ambientOcclusion ) );
	indirectSpecular = ( indirectSpecular * vec3<f32>( clamp( ( ambientOcclusion - ( 1.0 - pow( ( clamp( dot( transformedNormalView, positionViewDirection ), 0.0, 1.0 ) + ambientOcclusion ), exp2( ( - ( 1.0 - ( Roughness * -16.0 ) ) ) ) ) ) ), 0.0, 1.0 ) ) );
	totalDiffuse = vec3<f32>( 0.0, 0.0, 0.0 );
	totalDiffuse = ( directDiffuse + indirectDiffuse );
	totalSpecular = vec3<f32>( 0.0, 0.0, 0.0 );
	totalSpecular = ( directSpecular + indirectSpecular );
	outgoingLight = vec3<f32>( 0.0, 0.0, 0.0 );
	outgoingLight = ( totalDiffuse + totalSpecular );
	nodeVar63 = max( vec4<f32>( ( outgoingLight + EmissiveColor ), DiffuseColor.w ), vec4<f32>( 0.0 ) );
	Output = nodeVar63;

	// result

	output.color = nodeVar63;

	return output;

}
